//
//  SSBaseController.swift
//  Weibo项目
//
//  Created by vn on 16/7/19.
//  Copyright © 2016年 vn. All rights reserved.
//

import UIKit

class SSBaseController: UIViewController {

    //判断是否登录,根据状态加载不同的View
    let isLogin:Bool = OAuthViewModel.sharedViewModel.isLogin
    
    
    //没登录前View
    var visitorView = SSVisitorView()
    
    
    override func loadView() {
        
        // 判断加载不同的View
        isLogin ? (view = tableView) : setUpVisitorView()
        
       
}
    
    //MARK:创建visitorView
    func setUpVisitorView(){
         
        visitorView = SSVisitorView()
        visitorView.closure = {[weak self] in
            
            
            self?.loginClick()
            
        }
        
        view = visitorView
        
        //只有没有登录的时候才需要这个注册,登录按钮,所有在这里调用
            setNavButton()
        
    }
    
    //MARk:创建NavButton
    func setNavButton(){
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title:"注册", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title:"登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
        
    }
    
    //Nav按钮的监听方法
    func loginClick(){
        
        
        let oatuhVC = OAuthController()
        
        
        presentViewController(UINavigationController(rootViewController: oatuhVC), animated: true, completion: nil)
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
        
        
    }

    //懒加载tableView
    lazy var tableView:UITableView = UITableView()
    
    
}



